package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseAttrValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/7 9:09
 */
@RestController
@RequestMapping("/admin/product")
public class BaseAttrInfoController {
    @Autowired
    private BaseAttrInfoService attrInfoService;
    @Autowired
    private BaseAttrValueService attrValueService;
    /**
     * 根据分类id获取平台属性
     * @return
     */
    @RequestMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> getAttrInfoList(@PathVariable("category1Id") Long category1Id,
                                                      @PathVariable("category2Id") Long category2Id,
                                                      @PathVariable("category3Id") Long category3Id){
//        System.out.println("category1Id--->"+category1Id);
//        System.out.println("category2Id--->"+category2Id);
//        System.out.println("category3Id--->"+category3Id);
        List<BaseAttrInfo> attrInfoList = attrInfoService.getAttrInfoByCategoryId(category1Id,category2Id,category3Id);
        return Result.ok(attrInfoList);
    }

    /**
     * 根据分类id添加平台属性。新增修改二合一
     * @param attrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo attrInfo){
        attrInfoService.saveAttrInfo(attrInfo);
        return Result.ok();
    }

    /**
     * 根据平台属性id获取平台属性对象数据
     * @param attrId
     * @return
     */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        List<BaseAttrValue> values = attrValueService.getAttrValueList(attrId);
        return Result.ok(values);
    }
}
